package com.zhang.gmall.realtime.utils;

import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @title: 分词器
 * @author: zhang
 * @date: 2022/1/9 23:35
 */
public class KeywordUtil {
    public static List<String> splitKeyWord(String keyWord) throws IOException {
        //创建集合存放分词结果
        ArrayList<String> resultList = new ArrayList<>();

        StringReader reader = new StringReader(keyWord);

        IKSegmenter ikSegmenter = new IKSegmenter(reader, false);

        while (true){
            Lexeme next = ikSegmenter.next();
            if (next!=null){
                String word = next.getLexemeText();
                resultList.add(word);
            }else {
                break;
            }
        }
        return resultList;
    }


    public static void main(String[] args) throws IOException {
        System.out.println(splitKeyWord("数据仓库视频教程"));
    }
}
